package com.zzptc.my;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    Button btnreg;
    Button btnlogin;
    EditText etzh;
    EditText etmm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //实例化控件
        intiView();
        //处理事件
        event();
    }

    public void event(){
        //匿名内部类的写法
            btnreg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //吐丝方法，   跳转
                    Toast.makeText(MainActivity.this,"注册",Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(MainActivity.this,RegActivity.class);
                    //startActivity(intent);
                    startActivityForResult(intent,1);
                }
            });
            btnlogin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this,"登录",Toast.LENGTH_SHORT).show();
                }
            });
        }


    public void intiView() {
        //调取xml文件中的控件
        btnreg= findViewById(R.id.btn_zc);
        btnlogin=findViewById(R.id.btn_login);
        etzh=findViewById(R.id.etzh);
        etmm=findViewById(R.id.etmm);

    }

    //ait+insert
    //消亡时
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
//重写父类
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        String name=data.getStringExtra("name");
        Toast.makeText(this, "============"+name, Toast.LENGTH_SHORT).show();
    }
}
